home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / xprolog.arc / nrev < prev    next >
Encoding:
Text File  |  1987-10-12  |  593 b   |  29 lines

  1. /* Naive Reverse Benchmark    */
  2.  
  3.  
  4.  
  5. nrev:- write('list length: '),
  6.  
  7.     read(X),
  8.  
  9.     conslist(X, List),
  10.  
  11.     T1 is cputime,
  12.  
  13.     nreverse(List, R),
  14.  
  15.     T2 is cputime,
  16.  
  17.     T is T2 - T1,
  18.  
  19.     I is (X*(X+3))/2 + 1,
  20.  
  21.     LIPS is (I*1000)/T,
  22.  
  23.     write('LIPS= '),
  24.  
  25.     write(LIPS),
  26.  
  27.     write(' in '), write(T), write(' msec.'),
  28.  
  29.     nl,!.
  30.  
  31.     
  32.  
  33. nreverse([], []).
  34.  
  35. nreverse([X|L0],L) :- nreverse(L0, L1),
  36.  
  37.     concat(L1, [X], L).
  38.  
  39.  
  40.  
  41. conslist(0, []) :- !.
  42.  
  43. conslist(N, [N|L]) :-
  44.  
  45.     N1 is N-1,
  46.  
  47.     conslist(N1, L).
  48.  
  49.  
  50.  
  51. concat([],L,L).                % common append procedure
  52.  
  53. concat([X|L1],L2,[X|L3]) :- concat(L1,L2,L3).
  54.  
  55.  
  56.  
  57.